<?php
$v_move_record_to_leader = sizeof($arr_single_recordtype);
if($v_move_record_to_leader > 0) {
	$v_move_record_to_leader_cheched = $arr_single_recordtype['C_MOVE_TO_LEADER'];
}
//echo 'gggggggggggggg' . $v_move_record_to_leader_cheched.'<br>';
//exit;
set_time_limit(_CONST_REPORT_TIMEOUT);
$v_current_style_name = "round_row";
$v_current_date = "ng&#224;y ". date("d"). " th&#225;ng " . date("m")." n&#259;m " . date("Y");
$v_report_date = $_ISA_OWNER_REPORT_NAME;
$v_export_type = 1;
if(isset($_REQUEST['rad_exporttype'])){
	$v_export_type = $_REQUEST['rad_exporttype'];

}
$v_reporttype_filter = "";
if(isset($_REQUEST['hdn_reporttype_filter'])){
	$v_reporttype_filter = $_REQUEST['hdn_reporttype_filter'];

} 
//echo $v_reporttype_filter;
//Begin//Xay dung chuoi XML chua gia tri
$v_list_xml_tag = "";
if(isset($_REQUEST['hdn_list_xml_tag'])){
	$v_list_xml_tag = $_REQUEST['hdn_list_xml_tag'];
}
$v_list_xml_value = "";
if(isset($_REQUEST['hdn_list_xml_value'])){
	$v_list_xml_value = $_REQUEST['hdn_list_xml_value'];
}
$v_xml_str = '<?xml version="1.0" encoding="UTF-8"?><root><data_list>';
for ($i=0; $i<_list_get_len($v_list_xml_tag,_CONST_SUB_LIST_DELIMITOR); $i++){
	$v_xml_str = $v_xml_str ."<"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
	$v_xml_str = $v_xml_str .trim(_replace_XML_bad_char(_list_get_at($v_list_xml_value,$i,_CONST_SUB_LIST_DELIMITOR)));
	$v_xml_str = $v_xml_str ."</"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
}
$v_xml_str = $v_xml_str . "</data_list></root>";
//echo htmlspecialchars($v_xml_str)."<br>";
//Doc file chua cau truc cua bao cao

$v_report_xml_file = Get_text_from_array($arr_all_reporttype,'6','6','5', $v_reporttype_filter);
$v_report_xml_file = "../xml/report/".$v_report_xml_file;





if (!is_file($v_report_xml_file)){
	$v_report_xml_file = "../xml/report/bao_cao_chung.xml";
}
//$v_report_xml_file = "../xml/report/so_tiep_nhan_ho_so.xml";
$v_report_xml_string = _read_file($v_report_xml_file);
//echo htmlspecialchars($v_report_xml_string); exit;
//lay du lieu cua bao cao
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'report_sql';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_sql_string = _restore_XML_bad_char($table_struct_row["sql"]);
$v_sql_string = replace_tag_xml_value_in_sql($v_sql_string,$v_report_xml_string,$v_xml_str);
//echo $v_sql_string; exit; 
$v_group_by = $table_struct_row["group_by"];
$v_group_name = $table_struct_row["group_name"];
$v_xml_data_compare = $table_struct_row["xml_data"];
$v_calculate_total = $table_struct_row["calculate_total"];
$v_calculate_group = $table_struct_row["calculate_by_group"];
//Lay du lieu cua bao cao tu database
$arr_all_record = Query_Data_For_Colunm_name($v_sql_string);
//echo $v_sql_string;
//var_dump($arr_all_record); exit;
//Nhom du lieu theo mot the bat ky trong chuoi XML
//usort($arr_all_record,'sort_string_asc');
$v_count = sizeof($arr_all_record);
//lay cac thong tin tieu de cua form
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'table_struct_of_filter_form';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_form_title = $table_struct_row["form_title"];

// Lay ten file HTML mo ta phan tieu de cac cot
$v_report_label_file = trim($table_struct_row["table_header_file"]);
$v_first_col_width = $table_struct_row["first_col_width"];
$v_second_col_width = (100-$v_first_col_width)."%";
//Xau chua toan bo bao cao
$v_html_string = '';
//Phan than cua bao cao
//cac tieu de cot
$v_html_body = '';
$v_html_temp_width = '';
$v_html_temp_label = '';
$v_column = 0;
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'col';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
while ($table_struct_rec) { 
	$table_struct_row = $table_struct_rec->getRow();
	$v_type =  $table_struct_row["type"]; 
	$v_label = $table_struct_row["label"]; 
	$v_width = $table_struct_row["width"];
	$v_align = $table_struct_row["align"];
	//Lay danh sach do rong cac cot cua bang
	$v_html_temp_width = $v_html_temp_width  . '<col width="'.$v_width .'">';
	//Lay danh sach cac tieu de cua cot
	$v_html_temp_label = $v_html_temp_label . '<td class="header" align="'.$v_align.'">'.$v_label.'</td>';
	$arr_type[$v_column] = $v_type;
	$arr_align[$v_column] = $v_align;
	$table_struct_rec = $table_struct_rax->readRecord();
	$v_column ++;
}
//echo 'v_column'.$v_column; exit;
$v_width_col = 100/$v_column;
$v_html_col_list = $v_html_col_list .str_repeat("<col width:'$v_width_col%'>",$v_column);
//Neu ton tai file dinh dang tieu de cac cot
if ( (!is_null($v_report_label_file)) && ($v_report_label_file != "")){
	//Tieu de cot doc tu file HTML vao
	$v_report_label_file = _CONST_REPORT_LABEL_FILE_URL_PATH.$v_report_label_file;	
	$v_html_label_content = _read_file($v_report_label_file);	
	$v_html_body = $v_html_body.$v_html_label_content;
}else{
	$v_html_body = $v_html_body  . '<table class="report_table" style="width:99%" border="0" cellpadding="0" cellspacing="0">';
	
	$v_html_body = $v_html_body  . $v_html_temp_width;
	$v_html_body = $v_html_body  . '<tr>';
	$v_html_body = $v_html_body  . $v_html_temp_label;
	$v_html_body = $v_html_body  . '</tr>';
}
//Khoi tao thu tu cua danh sach va nhom 
$group_index=1;
$v_inc = 1;
if ($v_count >0){
	//Vong lap hien thi danh sach cac ho so
	$v_old_row = $arr_all_record[0];
	for ($i=0; $i< $v_column; $i++){
		$arr_calculate[$i] = 0;
	}
	for($row_index = 0;$row_index <$v_count ;$row_index++){
		$v_url = "";
		$v_recordset = $arr_all_record[$row_index];
		$v_received_record_xml_data = $arr_all_record[$row_index]['C_RECEIVED_RECORD_XML_DATA'];
		//echo htmlspecialchars($v_received_record_xml_data)."aaaaaaaaaaaaaaaaaaa";
		$v_recordtype_code = $arr_all_record[$row_index]['FK_RECORDTYPE'];
		$v_group_name_label = $arr_all_record[$row_index][$v_group_name];
		//Kiem tra xem ban ghi nay co thoa man dieu kien loc hay khong
		//if (!is_data_valid($v_recordset,$v_report_xml_string,$v_xml_str)){
		//	continue;
		//}
		if ($v_current_style_name == "odd_row"){
			$v_current_style_name = "round_row";
		}else{
			$v_current_style_name = "odd_row";
		}
		//Bat dau 1 dong			
		$table_struct_rax = new RAX(); 
		$table_struct_rec = new RAX(); 
		$table_struct_rax->open($v_report_xml_string);
		$table_struct_rax->record_delim = 'col';
		$table_struct_rax->parse();
		$table_struct_rec = $table_struct_rax->readRecord();
		$v_col_index = 0; 
		$v_html_body_row = '';
		//In tieu de cua nhom
		if (trim($v_group_by)!="" && $row_index == 0){	
			$v_html_body = $v_html_body  .'<tr class="'.$v_current_style_name.'" >';
			$v_html_body = $v_html_body  .'<td class="data"><B>'.$group_index.'</B></td>';
			$v_html_body = $v_html_body  .'<td class="data" colspan="'.($v_column-1).'"><B>'.$arr_all_record[$row_index][$v_group_by].'</B></td>';
			$v_html_body = $v_html_body  .'</tr>';
		}
		while ($table_struct_rec) { 
			$table_struct_row = $table_struct_rec->getRow();
			$v_type = $table_struct_row["type"];
			$v_width = $table_struct_row["width"];
			$v_align = $table_struct_row["align"];
			$v_xml_data = $table_struct_row["xml_data"];
			$v_calculate = $table_struct_row["calculate"];
			$v_compare_value = $table_struct_row["compare_value"];
			$v_column_name = $table_struct_row["column_name"];
			//Lay the xml chua noi dung can hien thi tu danh sach tuong ung voi ma
			$v_xml_tag_in_db = get_value_from_two_list($v_recordtype_code,$table_struct_row["recordtype_code_list"],$table_struct_row["xml_tag_in_db_list"]);
			$v_selectbox_option_sql = $table_struct_row["selectbox_option_sql"];
			$v_php_function = $table_struct_row["php_function"];
			$arr_xml_tag_in_db = explode(".",$v_xml_tag_in_db);
			if (sizeof($arr_xml_tag_in_db)>1){
				$v_received_record_xml_data = $arr_all_record[$row_index][$arr_xml_tag_in_db[0]];
				$v_xml_tag_in_db = $arr_xml_tag_in_db[1];
			}				
			if ($v_xml_data=="true" && $v_received_record_xml_data!="" && !is_null($v_received_record_xml_data)){
				$column_rax = new RAX(); 
				$column_rec = new RAX();
				$column_rax->open($v_received_record_xml_data);
				$column_rax->record_delim = 'data_list';
				$column_rax->parse();
				$column_rec = $column_rax->readRecord(); 
				$column_row = $column_rec->getRow();
				if ($v_xml_tag_in_db =="" && is_null($v_xml_tag_in_db)){
					$v_xml_tag_in_db = $table_struct_row["xml_tag_in_db"];
				}
				//echo $v_xml_tag_in_db."sssssss<br>";
				$v_value = _restore_XML_bad_char($column_row[$v_xml_tag_in_db]);
				
			}else{
				$v_value = $arr_all_record[$row_index][$v_column_name];
			}
			if ($v_type=="money"){
				$v_value = str_replace(",","",$v_value);
			}
			//In tu dong cua bao cao
			$v_html_body_row = $v_html_body_row . Report_Element_Type($v_type); 
			//Neu ma tinh so luong
			if ($v_calculate=="count"){
				if ((trim($v_compare_value)!="")&&(_list_have_element(trim($v_compare_value), trim($v_value),","))){
					$arr_calculate[$v_col_index] = $arr_calculate[$v_col_index] + 1;
					$arr_total_calculate[$v_col_index] = $arr_total_calculate[$v_col_index] + 1;
				}
			}elseif ($v_calculate=="sum"){//Neu tinh tong cac gia tri
				$v_value = str_replace(",","",$v_value);
				$arr_calculate[$v_col_index] = $arr_calculate[$v_col_index] + floatval($v_value);
				$arr_total_calculate[$v_col_index] = $arr_total_calculate[$v_col_index] + floatval($v_value);
			}else{						
				$arr_calculate[$v_col_index] = "";
				$arr_total_calculate[$v_col_index] = "";
			}
			$v_col_index ++;
			$table_struct_rec = $table_struct_rax->readRecord();
		}//End while
		$v_html_body = $v_html_body  .'<tr class="'.$v_current_style_name.'" >';
		$v_html_body = $v_html_body  .$v_html_body_row;
		$v_html_body = $v_html_body  .'</tr>';
		$v_inc ++;
		if (trim($v_group_by)!=""){	
			$v_current_row = $arr_all_record[$row_index+1];
			if ((sort_string_asc($v_old_row,$v_current_row)!=0)){
				//Khoi tao lai thu tu cua danh sach		
				$v_inc = 1;
				$group_index++;
				$v_html_temp = "";
				//Hien thi phan tinh toan theo nhom
				if ($v_calculate_group == "true"){
					for ($i=0,$n=sizeof($arr_calculate);$i < $n;$i++){
						if ($arr_calculate[$i]>=0){
							$v_type = $arr_type[$i];
							$v_align = $arr_align[$i];
							$v_value = $arr_calculate[$i];
							$arr_calculate[$i] = 0;
							if ($v_type=="money"){
								$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'">'.onegate_data_format($v_value).'&nbsp;</td>';
							}elseif($v_type=="identity"){
								$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'">&nbsp;</td>';
							}elseif($i==1){
								$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'"><B>C&#7897;ng:&nbsp;'.$v_group_name_label.'</B></td>';
							}else{
								$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'">'.$v_value.'&nbsp;</td>';
							}
						}
					}
				}
				$v_html_body = $v_html_body  .'<tr class="'.$v_current_style_name.'" >';
				$v_html_body = $v_html_body  .$v_html_temp;
				$v_html_body = $v_html_body  .'</tr>';
				//In tieu de cua nhom
				if (trim($v_group_by)!="" && $row_index<$v_count-1){	
					$v_html_body = $v_html_body  .'<tr class="'.$v_current_style_name.'" >';
					$v_html_body = $v_html_body  .'<td class="data"><B>'.$group_index.'</B></td>';
					$v_html_body = $v_html_body  .'<td class="data" colspan="'.($v_column-1).'"><B>'.$arr_all_record[$row_index+1][$v_group_by].'</B></td>';
					$v_html_body = $v_html_body  .'</tr>';
				}
	
				
			}//End if							
			$v_old_row = $v_current_row;
		}							
		//Ket thuc mot dong
	}//End for
}//End if
//Hien thi phan tinh toan tong
if ($v_calculate_total=="true"){
	$v_html_temp = "";
	for ($i=0;$i < $v_col_index;$i++){
		if ($arr_total_calculate[$i]>=0){
			$v_type = $arr_type[$i];
			$v_align = $arr_align[$i];
			$v_value = $arr_total_calculate[$i];
			if ($v_type=="money"){
				$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'">'.onegate_data_format($v_value).'&nbsp;</td>';
			}elseif($v_type=="identity"){
				$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'">&nbsp;</td>';
			}elseif($i==1){
				$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'"><B>T&#7893;ng c&#7897;ng&nbsp;</B></td>';			
			}else{
				$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'">'.$v_value.'&nbsp;</td>';
			}
		}
	}
	$v_html_body = $v_html_body  .'<tr class="'.$v_current_style_name.'" >';
	$v_html_body = $v_html_body  .$v_html_temp;
	$v_html_body = $v_html_body  .'</tr>';
}
if ($v_current_style_name == "odd_row"){
	$v_next_style_name = "round_row";
}else{
	$v_next_style_name = "odd_row";
}
//Ket thuc ban bang cua bao cao
$v_html_body = $v_html_body  .'</table>';
//Het phan than cua bao cao
//Lay cac thong tin ve tieu de cua bao cao
$v_html_header = '';
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'report_header';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_report_unit = $table_struct_row["report_unit"];
//$v_report_date = $table_struct_row["report_date"];
$v_large_title = $table_struct_row["large_title"];
$v_small_title = $table_struct_row["small_title"];
$v_html_header = $v_html_header  .'<table width="99%" border="0" cellpadding="0" cellspacing="0">';
//$v_html_header = $v_html_header  .'<col width:"20%"><col width:"20%"><col width:"20%"><col width:"20%"><col width:"20%">';
$v_html_header = $v_html_header  . $v_html_col_list;
if(!$v_move_record_to_leader_cheched){
	$v_html_header = $v_html_header  .'<tr valign="top"><td align="center" class="report_unit_name" colspan="'.floor($v_column/2).'">'.$_ISA_OWNER_NAME."<br>".$v_report_unit.'</td>';
	$v_html_header = $v_html_header  .'<td align="center" class="freedom_republic" colspan="'.($v_column-floor($v_column/2)).'">'.CONST_REPORT_REPUBLIC_TITLE."<br>".CONST_REPORT_FREEDOM_TITLE.'</td>';
	$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" colspan="'.$v_column.'">&nbsp;</td>';
	$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" colspan="'.$v_column.'">==============***==============</td>';
	$v_html_header = $v_html_header  .'</tr><tr><td align="right" class="date" colspan="'.$v_column.'"><i>'.$v_report_date.', '.$v_current_date.'</i></td>';
}
	$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" colspan="'.$v_column.'">&nbsp;</td>';
	$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="title" colspan="'.$v_column.'">'.$v_large_title.'</td>';
	$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="sub_title" colspan="'.$v_column.'">'.$v_small_title.'</td>';
	$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" colspan="'.$v_column.'">&nbsp;</td>';
	$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" colspan="'.$v_column.'">&nbsp;</td>';
	$v_html_header = $v_html_header  .'</tr></table>';
//Het phan tieu de cua bao cao
//Phan chua cac tieu thuc loc bao cao
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'row';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
while ($table_struct_rec) { 
	$table_struct_row = $table_struct_rec->getRow();
	$v_tag_list = $table_struct_row["tag_list"];
	$v_row_id = $table_struct_row["row_id"];
	$arr_tag = explode(",", $v_tag_list);
	//Bang chua mot dong cua form
	$v_html_header = $v_html_header . "<table width='99%'  border='0' cellspacing='0' cellpadding='0'>";
	$v_html_table = "";
	$v_html_tag = "";									
	for($i=0;$i < sizeof($arr_tag);$i++){
		$formfield_rax = new RAX(); 
		$formfield_rec = new RAX(); 
		$formfield_rax->open($v_report_xml_string);
		$formfield_rax->record_delim = $arr_tag[$i];
		$formfield_rax->parse();
		$formfield_rec = $formfield_rax->readRecord(); 
		$formfield_row = $formfield_rec->getRow(); 
		$v_label = $formfield_row["label"];
		$v_type = $formfield_row["type"];
		$v_dataformat = $formfield_row["data_format"];
		$v_width = $formfield_row["width"];
		$v_row = $formfield_row["row"];
		$v_max = $formfield_row["max"];
		$v_min = $formfield_row["min"];
		$v_maxlength = $formfield_row["maxlength"];
		$v_note = $formfield_row["note"];
		$v_message = $formfield_row["message"];
		$v_optional = $formfield_row["optional"];
		$v_xml_tag_in_db = $formfield_row["xml_tag_in_db"];
		$v_js_function_list = $formfield_row["js_function_list"];
		$v_js_action_list = $formfield_row["js_action_list"];
		$v_readonly_in_edit_mode = $formfield_row["readonly_in_edit_mode"];
		$v_disabled_in_edit_mode = $formfield_row["disabled_in_edit_mode"];
		if ($v_xml_str!=""){
			$column_rax = new RAX(); 
			$column_rec = new RAX();
			$column_rax->open($v_xml_str);
			$column_rax->record_delim = 'data_list';
			$column_rax->parse();
			$column_rec = $column_rax->readRecord(); 
			$column_row = $column_rec->getRow();
			$v_value = _restore_XML_bad_char($column_row[$v_xml_tag_in_db]); 
		}
		if ($v_type=="selectbox"){
			$v_selectbox_option_sql = $formfield_row["selectbox_option_sql"];
			$v_selectbox_id_column = $formfield_row["selectbox_option_id_column"];
			$v_selectbox_name_column = $formfield_row["selectbox_option_name_column"];
		}
		if ($v_type=="checkboxmultiple"){
			$v_checkbox_multiple_sql = $formfield_row["checkbox_multiple_sql"];
			$v_checkbox_multiple_id_column = $formfield_row["checkbox_multiple_id_column"];
			$v_checkbox_multiple_name_column = $formfield_row["checkbox_multiple_name_column"];
		}
		$v_html_table = $v_html_table . "<col width='$v_first_col_width'>" . "<col width='$v_second_col_width'>";		
		$v_html_tag = $v_html_tag . Generate_HTML_Output();		
	}
	$v_html_header = $v_html_header .  $v_html_table . "<tr><td class='normal_label' align='center' colspan='$v_column'>" . $v_html_tag."</td></tr>";
	$v_html_header = $v_html_header . "</table>";
	$table_struct_rec = $table_struct_rax->readRecord();
}
$v_html_header = $v_html_header . "<table width='99%'  border='0' cellspacing='0' cellpadding='0'>";
$v_html_header = $v_html_header . "<tr><td colspan='$v_column'>&nbsp;</td></tr>";
$v_html_header = $v_html_header . "</table>";
//Het phan bang chua cac tieu thuc loc
//lay cac thong tin phan cuoi cua bao cao
$v_html_footer = '';
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'report_footer';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_report_creator = $table_struct_row["report_creator"];
$v_report_approver = $table_struct_row["report_approver"];
$v_report_signer = $table_struct_row["report_signer"];
$v_html_footer = $v_html_footer  .'<table width="99%" border="0" cellspacing="0" cellpadding="0">';
$v_html_footer = $v_html_footer  . $v_html_col_list;
$v_html_footer = $v_html_footer  .'<tr><td class="normal_label" colspan="'.$v_column.'">&nbsp;</td></tr><tr>';
$v_html_footer = $v_html_footer  .'<tr><td class="normal_label" colspan="'.$v_column.'">&nbsp;</td></tr><tr>';
$v_html_footer = $v_html_footer  .'<td class="normal_label">&nbsp;</td>';
$v_html_footer = $v_html_footer  .'<td align="center" class="creator">'.$v_report_creator.'&nbsp;</td>';
$v_html_footer = $v_html_footer  .'<td align="center" class="approver">'.$v_report_approver.'&nbsp;</td>';
$v_html_footer = $v_html_footer  .'<td align="center" class="signer">'.$v_report_signer.'&nbsp;</td>';
$v_html_footer = $v_html_footer  .'</tr></table>';

//ket hop cac phan cua bao cao
$v_html_string = $v_html_string.$v_html_header.$v_html_body.$v_html_footer;
//echo '<table cellpadding="0" cellspacing="0" width="100%" border="0"><tr><td>&nbsp;</td></tr></table>';
//echo htmlspecialchars(str_replace('report_table','list_table_print',$v_html_string));
str_replace('report_table','list_table_print',$v_html_string);
echo $v_html_string; 

//Xuat ra file theo dinh dang html
$v_style_file = "report_style.css";
$v_str_style = _read_file($v_style_file);
//Phan dau cua chuoi html
$v_html_content = '<html xmlns:o="urn:schemas-microsoft-com:office:office"
					xmlns:x="urn:schemas-microsoft-com:office:excel">
					<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
$v_html_content = $v_html_content.'<style type=text/css><!--'.$v_str_style.'--></style>';
//Phan dinh dang cac bang cua Exel
$v_html_content = $v_html_content.'<!--[if gte mso 9]><xml>
									 <x:ExcelWorkbook>
									  <x:ExcelWorksheets>
									   <x:ExcelWorksheet>
										<x:Name>Report</x:Name>
										<x:WorksheetOptions>
										 <x:Print>
										  <x:ValidPrinterInfo/>
										  <x:HorizontalResolution>600</x:HorizontalResolution>
										  <x:VerticalResolution>600</x:VerticalResolution>
										 </x:Print>
										 <x:PageBreakZoom>100</x:PageBreakZoom>
										 <x:Selected/>
										 <x:Panes>
										  <x:Pane>
										   <x:Number>0</x:Number>
										   <x:ActiveRow>0</x:ActiveRow>
										   <x:ActiveCol>0</x:ActiveCol>
										  </x:Pane>
										 </x:Panes>
										 <x:ProtectContents>False</x:ProtectContents>
										 <x:ProtectObjects>False</x:ProtectObjects>
										 <x:ProtectScenarios>False</x:ProtectScenarios>
										</x:WorksheetOptions>
										<x:Sorting>
										 <x:Sort>ma</x:Sort>
										</x:Sorting>
									   </x:ExcelWorksheet>
									  </x:ExcelWorksheets>
									  <x:WindowHeight>9345</x:WindowHeight>
									  <x:WindowWidth>15180</x:WindowWidth>
									  <x:WindowTopX>120</x:WindowTopX>
									  <x:WindowTopY>60</x:WindowTopY>
									  <x:ProtectStructure>False</x:ProtectStructure>
									  <x:ProtectWindows>False</x:ProtectWindows>
									 </x:ExcelWorkbook>
									</xml><![endif]-->';

$v_html_content = $v_html_content.'</head><body>'.$v_html_string.'</body>';
$v_html_content = $v_html_content.'</html>';
switch($v_export_type) {
	case 1;
		$v_export_filename = "report.htm";
		break;
	case 2;
		$v_html_content = str_replace('text/html','application/msword',$v_html_content);
		$v_export_filename = "report.doc";
		break;
	case 3;
		$v_export_filename = "report.xls";
		$v_html_content = str_replace('text/html','application/vnd.ms-excel',$v_html_content);		
		break;
	default:
		$v_export_filename = "report.htm";
		break;	
}	
_write_file($v_export_filename ,$v_html_content);

?>
<form action='index.php' method='post' name='f_dsp_single_conditions'>
<table width='100%' border='0' cellspacing='0' cellpadding='0'>
	<tr><td height="20pt"></td></tr>
	<tr align="center">
		<td colspan="5">
			<input type='hidden' name='fuseaction' value='DISPLAY_SINGLE_CONDITIONS'>
			<!--
			<input type='button' class='normal_button' name="btn_back" value='<?php echo _CONST_BACK_BUTTON;?>' onClick="btn_back_onclick('DISPLAY_SINGLE_CONDITIONS')" onKeyDown="change_focus(document.forms(0),this)">
			-->
		</td>	
	</tr>
</table>
</form>
<script language="JavaScript">
	//document.forms(0).submit();
	goto_url("<?php echo $v_export_filename ?>",1);
</script>

